<template>

	<up-loading-page loading-mode="spinner" :loading="!loadState"></up-loading-page>
	<view class="user-container pageBg" v-if='loadState'>
		<!-- 未登录 -->
		<view class="userinfo">
			<view v-if="noLog">
				<view class="avator">
					<image src="../../static/logo.png" mode="aspectFill"></image>
				</view>
				<view class="goLog" @click="onLogin">
					<text>去登陆</text>
				</view>
			</view>
			<view v-else>
				<view class="avator">
					<up-avatar size="170rpx"
						:src="userInfo.userid[0].avatar_file ? userInfo.userid[0].avatar_file.url :'/static/noPic.png'"
						shape="square"></up-avatar>
				</view>
				<view class="username">
					<text>{{userInfo.userid[0].username}}</text>
				</view>
			</view>

		</view>

		<view class="section">
			<view class="list">

				<view class="row" @click="userPublic">
					<view class="left">
						<up-icon name="file-text-fill" size="26" color="#98c379"></up-icon>
						<view class="text">我的发布</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>

				<view class="row" @click="setting">
					<view class="left">
						<up-icon name="setting-fill" size="24" color="#98c379"></up-icon>
						<view class="text">设置</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	const db = uniCloud.database()
	const loadState = ref(false)
	const userInfo = ref(Object)
	const noLog = ref(false)
	// 去登陆
	const onLogin = () => {
		uni.navigateTo({
			url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
		})
	}
	// setting
	const setting = () => {
		uni.navigateTo({
			url: '/pages/my/setting/index'
		})
	}
	// 发布中心
	const userPublic = () => {
		uni.navigateTo({
			url: '/pages/my/setting/userPublic/index'
		})
	}
	// 登录权限
	let artTemp = db.collection('articles').field("userid").getTemp();
	let usetTemp = db.collection('uni-id-users').field("_id,username,avatar_file").getTemp()
	db.collection(artTemp, usetTemp).where('userid._id == $cloudEnv_uid')
		.get({
			getOne: true
		})
		.then(res => {
			console.log(res);
			userInfo.value = res.result.data
			loadState.value = true
		})
		.catch(err => {
			console.log(err);
			noLog.value = true
		})
</script>

<style lang="scss">
	.user-container {
		// padding-top: var(--status-bar-hight) ;
		.userinfo {
			// height: 300rpx;
			padding-top: 10vh ;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			.avator {

				.u-avatar {
					width: 100%;
					height: 100%;
				}

				image {
					border-radius: 50%;
					height: 100%;
					width: 100%;
				}
			}

			.goLog {
				margin: 20rpx 0;
				border-radius: 20rpx;
				text-align: center;
				flex: 1;
				padding: 20rpx 0;
				background-color: #96e6a1;
				box-shadow: 0 10rpx 10rpx 0 #333;

				text {
					font-size: 30rpx;
					color: #676767;
				}
			}
			.username{
				text-align: center;
				padding: 10rpx;
				text{
					font-size: 30rpx;
					font-weight: bold;
				}
			}
		}


		.section {
			width: 690rpx;
			margin: 50rpx auto;
			border-radius: 10rpx;
			border: 1rpx solid #eee;
			box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

			.list {
				.row {
					display: flex;
					height: 100rpx;
					padding: 0 30rpx;
					background: #fff;
					position: relative;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1rpx solid #eee;

					&:last-child {
						border-bottom: 0;
					}

					.left {
						display: flex;
						align-items: center;

						.text {
							color: #666;
							padding: 0 10rpx;
						}
					}

					.right {
						display: flex;
						align-items: center;

						.text {
							color: #aaa;
							font-size: 28rpx;
						}
					}

					button {
						top: 0;
						left: 0;
						width: 100%;
						opacity: 0;
						height: 100rpx;
						position: absolute;
					}
				}
			}
		}
	}
</style>